<template>
  <div :id="id" :class="className" :style="{ height: height, width: width }" />
</template>

<script>
import echarts from "echarts";
import resize from "./mixins/resize";

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: "chart",
    },
    id: {
      type: String,
      default: "chart",
    },
    width: {
      type: String,
      default: "200px",
    },
    height: {
      type: String,
      default: "200px",
    },
  },
  data() {
    return {
      chart: null,
    };
  },
  created() {},
  mounted() {
    this.initChart();
  },
  beforeDestroy() {
    if (!this.chart) {
      return;
    }
    this.chart.dispose();
    this.chart = null;
  },
  methods: {
    initChart() {
      this.chart = echarts.init(document.getElementById(this.id));
      this.chart.setOption({
        tooltip: {
          trigger: "axis",
          backgroundColor: "transparent", //标题背景色
          borderColor: "#fff", //边框颜色
          borderWidth: 0, //边框线宽
          padding: 5,
          borderRadius: 6,
          axisPointer: {
            lineStyle: {
              color: {
                type: "linear",
                x: 0,
                y: 0,
                x2: 0,
                y2: 1,
                colorStops: [
                  {
                    offset: 0,
                    color: "rgba(255,255,255,0)", // 0% 处的颜色
                  },
                  {
                    offset: 0.5,
                    color: "rgba(255,255,255,1)", // 100% 处的颜色
                  },
                  {
                    offset: 1,
                    color: "rgba(255,255,255,0)", // 100% 处的颜色
                  },
                ],
                global: false, // 缺省为 false
              },
            },
          },
          formatter: function (params) {
            return `<div style="background:#fff;padding: 20px;border-radius: 6px;
box-shadow: 0px 0px 12px 0px rgba(14,23,38,0.1);">
                    <div style="display: flex; align-items: center;
 padding-bottom: 15px;
                    margin-bottom: 15px;
                    border-bottom: 1px solid #ebedf2;">
                    <span
                    style="
                        width: 12px;
                        height: 12px;                     
                        background: linear-gradient(-90deg, #2945CB, #2A67E4, #3798FD);
                        border-radius: 2px;
                        margin-right: 10px
                    "
                    ></span>
                    <i style="color: #8fa1c9">每月计划安排</i>
                    <p style="font-weight: 800; margin-left: 40px;color:#111;flex: 1;
    text-align: right;">147000</p>
                    </div>
                    <div style="display: flex; align-items: center;
 padding-bottom: 15px;
                    margin-bottom: 15px;
                    border-bottom: 1px solid #ebedf2;">
                    <span
                    style="
                        width: 12px;
                        height: 12px;
                        background: #31C670;
                        border-radius: 2px;
                        margin-right: 10px
                    "
                    ></span>
                    <i style="color: #8fa1c9">系统A品完成数量</i>
                    <p style="font-weight: 800; margin-left: 40px;color:#111;flex: 1;
    text-align: right;">147000</p>
                    </div>
                    <div style="display: flex; align-items: center;">
                    <span
                    style="
                        width: 12px;
                        height: 12px;
                        background: #FF8B17;
                        border-radius: 2px;
                        margin-right: 10px
                    "
                    ></span>
                    <i style="color: #8fa1c9">月产能情况</i>
                    <p style="font-weight: 800; margin-left: 40px;color:#111;flex: 1;
    text-align: right;">147000</p>
                    </div>
                </div>    
                `;
          },
        },
        legend: {
          x: "left",
          itemWidth: 12, // 图例图形宽度
          itemHeight: 12,
        },
        grid: {
          left: "0%",
          right: "0%",
          bottom: "3%",
          containLabel: true,
        },
        xAxis: [
          {
            type: "category",
            data: [
              "平度一厂",
              "平度二厂",
              "平度三厂",
              "平度四厂",
              "平度五厂",
              "平度六厂",
              "平度七厂",
            ],
            axisTick: {
              show: false, // 是否显示坐标轴轴线
            },
            axisLabel: {
              color: "#282828",
            },
            splitLine: {
              show: false,
            },
            boundaryGap: true,
            axisLine: {
              //坐标轴轴线相关设置。
              show: true,
              inside: false,
              lineStyle: {
                color: "#EBEDF2",
              },
            },
          },
        ],
        yAxis: [
          {
            type: "value",
            axisLabel: {
              //坐标轴刻度标签的相关设置。
              show: true,
              textStyle: {
                color: "#737373",
              },
            },
            axisLine: {
              show: false,
            },
            axisTick: {
              show: false,
            },
            splitLine: {
              lineStyle: {
                color: "rgba(131,101,101,0.2)",
              },
            },
          },
        ],
        series: [
          {
            name: "邮件营销",
            type: "line",
            smooth: false,
            showSymbol: true,
            symbolSize: 8,
            zlevel: 20,
            itemStyle: {
              color: "#FF8B17",
              borderColor: "#FF8B17",
            },
            lineStyle: {
              normal: {
                width: 2,
                color: "#FF8B17",
              },
            },
            data: [320, 332, 301, 334, 390, 330, 320],
          },
          {
            name: "直接访问",
            type: "bar",
            barMaxWidth: 12,
            zlevel: 10,
            // barGap: '100%',
            itemStyle: {
              normal: {
                color: {
                  type: "linear",
                  x: 0,
                  y: 0,
                  x2: 0,
                  y2: 1,
                  colorStops: [
                    {
                      offset: 0,
                      color: "#3798FD",
                    },
                    {
                      offset: 1,
                      color: "#2945CB",
                    },
                  ],
                },
                barBorderRadius: [30, 30, 0, 0],
              },
            },
            data: [320, 332, 301, 334, 390, 330, 320],
          },

          {
            name: "搜索引擎",
            type: "bar",
            barMaxWidth: 12,
            zlevel: 10,
            // barGap: '100%',
            itemStyle: {
              normal: {
                color: {
                  type: "linear",
                  x: 0,
                  y: 0,
                  x2: 0,
                  y2: 1,
                  colorStops: [
                    {
                      offset: 0,
                      color: "#31C670",
                    },
                    {
                      offset: 1,
                      color: "#31C670",
                    },
                  ],
                },
                barBorderRadius: [30, 30, 0, 0],
              },
            },
            data: [862, 1018, 964, 1026, 1679, 1600, 1570],
          },
        ],
      });
    },
  },
};
</script>

<style scoped lang="less"></style>
